<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="org.json.simple.JSONObject"%>
<%@ page import="java.io.*,java.util.*, javax.servlet.*" %>
<%@ page import="org.apache.commons.lang.*" %>
<%@ page import="org.apache.commons.codec.digest.DigestUtils" %>

<%
	String nonceStr = RandomStringUtils.randomAlphanumeric(32);
%>
<%
    JSONObject obj=new JSONObject();
    JSONObject obj2=new JSONObject();
   	String strBsns = "failure";
   	String strDesc = "you need ticket";
    if(null!=(String)request.getAttribute("ticket")){
    	strBsns = "success";
    	strDesc = "logined with ticket";
    	obj2.put("debug",false);
	    obj2.put("beta",false);
	    obj2.put("jsApiList","[\"openLocation\",\"updateAppMessageShareData\",\"updateTimelineShareDataonMenuShareWeibo\",\"onMenuShareTimeline\",\"onMenuShareAppMessage\",\"onMenuShareQQ\",\"onMenuShareQZone\"]");
	   	obj2.put("appId",(String)request.getAttribute("appId"));
	   	String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	   	
	 	obj2.put("nonceStr",nonceStr);
	 	Date date = new Date();
	 	obj2.put("timestamp",date.getTime());
	 	obj2.put("url",(String)request.getParameter("location"));
	 	
	 	String strSecr = "jsapi_ticket="+(String)request.getAttribute("ticket") +
	 						"&"+"noncestr="+nonceStr +
	 						"&"+"timestamp="+date.getTime() +
	 						"&"+"url="+(String)request.getParameter("location");
	 	
	 	obj2.put("signature",DigestUtils.sha1Hex(strSecr));
	    obj.put("data",obj2);
    }
    
    obj.put("businessCode",strBsns);
    obj.put("description",strDesc);
    obj.put("t",(String)request.getAttribute("openid")+" login");
    out.print(obj);
    out.flush();
    
%>